<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>身份证号码解析</title>
<link rel="stylesheet" href="ch3.css">
</head>
<body>
<div class="hh">
<div class="h1">
<label for="idCard">请输入身份证号码：</label>
<input type="text" id="idCard" placeholder="请输入18位身份证号码">
<button onclick="parseIdCard()">解析</button>

<div id="birthday"></div>
</div>
</div>
<script>
    function parseIdCard() {
        // 获取文本框中的身份证号码
        let idCard = document.getElementById('idCard').value;
        
        // 检查是否为18位身份证号码
        if (idCard.length !== 18) {
            alert('请输入18位身份证号码！');
            return;
        }
        
        // 截取出生日期部分
        let birthYear = idCard.slice(6, 10);
        let birthMonth = idCard.slice(10, 12);
        let birthDay = idCard.slice(12, 14);
        
        // 组合年月日并显示在页面上
        let birthday = `${birthYear}年${birthMonth}月${birthDay}日`;
        document.getElementById('birthday').innerText = birthday;
    }
</script>

</body>
</html>